import {defineStore} from 'pinia';

export const useUserStore = defineStore('UserStore', {
	state: () => ({
		userInfo: null, // 用户信息
		isLogin: false, // 登录状态
		gameList: [],
		Steam: null,
		BotText: '',
		UserText: ''
	}),
	persist: {
		enabled: true,
		strategies: [{
			key: 'user',
			storage: localStorage,
		}]
	},
	getters: {
		// 获取用户信息
		getUserInfo: (state) => state.userInfo,
		// 获取登录状态
		isLoggedIn: (state) => state.isLogin,
		//获取玩家游戏列表
		getGame: (state) => state.gameList,
		getSteam: (state) => state.Steam,
		getBot: (state) => state.BotText,
		getUserText: (state) => state.UserText,
	},

	actions: {
		// 登录
		login(userInfo) {
			this.userInfo = userInfo;
			this.isLogin = true;
		},
		// 登出
		logout() {
			this.userInfo = null;
			this.isLogin = false;
		},
		setGames(games) {
			this.gameList = games;
		},
		removeGame() {
			this.gameList = null
		},
		setSteam(team) {
			this.Steam = team;
		},
		clearSteam() {
			this.Steam = null;
		},
		setBotText(botText) {
			this.BotText = botText;
		},
		setUserText(userText) {
			this.UserText = userText;
		}
	},
});